package com.fyzk.activity.lottery.basketball;

import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.tyjc.lottery.R;


public class JCLQSelectPlayMethodPop extends PopupWindow implements OnCheckedChangeListener {

	private LinearLayout llNoDan;
	private CheckBox sf_lq,sfc_lq,rfsf_lq,hg_lq,dxf_lq;
	private CheckBox sf_lq_d,sfc_lq_d,rfsf_lq_d,dxf_lq_d;

	public JCLQSelectPlayMethodPop(Context context,int width, int height) {
		this(context,width,height,false);
	}

	public JCLQSelectPlayMethodPop(Context context,int width, int height, boolean isDanGuanInto) {
		super(width, height);
		View view = View.inflate(context, R.layout.layout_selectplaymethod_jclq, null);
		this.setContentView(view);
		initView(view,isDanGuanInto);
		this.setOutsideTouchable(true);
		this.setBackgroundDrawable(context.getResources().getDrawable(R.color.transparent));
		// 设置此参数获得焦点，否则无法点击
		this.setFocusable(true);
	}

	private void initView(View view,boolean isDanGuanInto) {
		llNoDan = (LinearLayout) view.findViewById(R.id.llNoDan);
		sf_lq = (CheckBox)view.findViewById(R.id.cb_selectplaymethod_lq_sf);
		sf_lq_d = (CheckBox)view.findViewById(R.id.cb_selectplaymethod_lq_sf_d);
		sfc_lq = (CheckBox)view.findViewById(R.id.cb_selectplaymethod_lq_sfc);
		sfc_lq_d = (CheckBox)view.findViewById(R.id.cb_selectplaymethod_lq_sfc_d);
		hg_lq = (CheckBox)view.findViewById(R.id.cb_selectplaymethod_hg_lq);
		dxf_lq = (CheckBox)view.findViewById(R.id.cb_selectplaymethod_dxf_lq);
		dxf_lq_d = (CheckBox)view.findViewById(R.id.cb_selectplaymethod_dxf_lq_d);
		rfsf_lq = (CheckBox)view.findViewById(R.id.cb_selectplaymethod_lq_rqsf);
		rfsf_lq_d = (CheckBox)view.findViewById(R.id.cb_selectplaymethod_lq_rqsf_d);
		sf_lq.setOnCheckedChangeListener(this);
		sfc_lq.setOnCheckedChangeListener(this);
		hg_lq.setOnCheckedChangeListener(this);
		dxf_lq.setOnCheckedChangeListener(this);
		rfsf_lq.setOnCheckedChangeListener(this);
		sf_lq_d.setOnCheckedChangeListener(this);
		sfc_lq_d.setOnCheckedChangeListener(this);
		dxf_lq_d.setOnCheckedChangeListener(this);
		rfsf_lq_d.setOnCheckedChangeListener(this);
		if (isDanGuanInto) {
			sfc_lq_d.setChecked(true);
			llNoDan.setVisibility(View.GONE);
		}else{
			hg_lq.setChecked(true);
			llNoDan.setVisibility(View.VISIBLE);
		}
	}
	
	private void clearChecked(){
		sf_lq.setOnCheckedChangeListener(null);
		sfc_lq.setOnCheckedChangeListener(null);
		hg_lq.setOnCheckedChangeListener(null);
		dxf_lq.setOnCheckedChangeListener(null);
		rfsf_lq.setOnCheckedChangeListener(null);
		sf_lq_d.setOnCheckedChangeListener(null);
		sfc_lq_d.setOnCheckedChangeListener(null);
		dxf_lq_d.setOnCheckedChangeListener(null);
		rfsf_lq_d.setOnCheckedChangeListener(null);
		sf_lq.setChecked(false);
		sfc_lq.setChecked(false);
		hg_lq.setChecked(false);
		dxf_lq.setChecked(false);
		rfsf_lq.setChecked(false);
		sf_lq_d.setChecked(false);
		sfc_lq_d.setChecked(false);
		dxf_lq_d.setChecked(false);
		rfsf_lq_d.setChecked(false);
		sf_lq.setOnCheckedChangeListener(this);
		sfc_lq.setOnCheckedChangeListener(this);
		hg_lq.setOnCheckedChangeListener(this);
		dxf_lq.setOnCheckedChangeListener(this);
		rfsf_lq.setOnCheckedChangeListener(this);
		sf_lq_d.setOnCheckedChangeListener(this);
		sfc_lq_d.setOnCheckedChangeListener(this);
		dxf_lq_d.setOnCheckedChangeListener(this);
		rfsf_lq_d.setOnCheckedChangeListener(this);
	}
	
	
	
	public void setOnWFCheckChangedListener(OnWFCheckChangedListener listener ){
		this.listener = listener;
	}
	
	
	private OnWFCheckChangedListener listener = null;
	
	public interface OnWFCheckChangedListener{
		void onWFCheckChange(int id, boolean isChecked);
	}
	
	@Override
	public void showAtLocation(View parent, int gravity, int x, int y) {
		super.showAsDropDown(parent);
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		clearChecked();
		buttonView.setOnCheckedChangeListener(null);
		buttonView.setChecked(isChecked);
		buttonView.setOnCheckedChangeListener(this);
		if(listener!=null){
			listener.onWFCheckChange(buttonView.getId(),isChecked);
		}
		//已选中的玩法CheckBox 不能再点击
		sf_lq.setEnabled(!sf_lq.isChecked());
		sfc_lq.setEnabled(!sfc_lq.isChecked());
		hg_lq.setEnabled(!hg_lq.isChecked());
		dxf_lq.setEnabled(!dxf_lq.isChecked());
		rfsf_lq.setEnabled(!rfsf_lq.isChecked());
		sf_lq_d.setEnabled(!sf_lq_d.isChecked());
		sfc_lq_d.setEnabled(!sfc_lq_d.isChecked());
		dxf_lq_d.setEnabled(!dxf_lq_d.isChecked());
		rfsf_lq_d.setEnabled(!rfsf_lq_d.isChecked());
	}

}
